--- 注：一定要开启热部署 lua_code_cache，否则初始化代码每次执行，整体逻辑不生效，且性能损耗
--- https://github.com/openresty/lua-resty-lrucache

local _M = {}

lrucache = require "resty.lrucache"

c, err = lrucache.new(200) -- allow up to 200 items in the cache
ngx.say("count=init")
if not c then
    error("failed to create the cache: " .. (err or "unknown"))
end

function _M.go()
    count = c:get("count")
    c:set("count", 100)
    ngx.say("count=", count, "--<br/>")

    if not count then
        c:set("count", 1)
        ngx.say("lazy set i ", c:get("count"), "<br/>")
    else
        c:set("count", count + 1)
        ngx.say("count=", count, "<br/>")
    end
end

return _M